package co.yixiang.common.core.utils;///**
// * Copyright (C) 2018-2020
// * All rights reserved, Designed By www.yixiang.co
//
// */
//package co.yixiang.common.base.utils;
//
//import cn.hutool.json.JSONObject;
//
//import co.yixiang.common.base.exception.BadRequestException;
//import org.apache.tomcat.util.net.openssl.ciphers.Authentication;
//import org.springframework.http.HttpStatus;
//
///**
// * 获取当前登录的用户
// * @author Zheng Jie
// * @date 2019-01-17
// */
//public class SecurityUtils {
//
//    public static UserDetails getUserDetails() {
//        final Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
//        if (authentication == null) {
//            throw new BadRequestException(HttpStatus.UNAUTHORIZED, "当前登录状态过期");
//        }
//        if (authentication.getPrincipal() instanceof UserDetails) {
//            UserDetails userDetails = (UserDetails) authentication.getPrincipal();
//            UserDetailsService userDetailsService = SpringContextHolder.getBean(UserDetailsService.class);
//            return userDetailsService.loadUserByUsername(userDetails.getUsername());
//        }
//        throw new BadRequestException(HttpStatus.UNAUTHORIZED, "找不到当前登录的信息");
//    }
//
//    /**
//     * 获取系统用户名称
//     * @return 系统用户名称
//     */
//    public static String getUsername(){
//        final Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
//        if (authentication == null) {
//            throw new BadRequestException(HttpStatus.UNAUTHORIZED, "当前登录状态过期");
//        }
//        UserDetails userDetails = (UserDetails) authentication.getPrincipal();
//        return userDetails.getUsername();
//    }
//
//    /**
//     * 获取系统用户id
//     * @return 系统用户id
//     */
//    public static Long getUserId(){
//        Object obj = getUserDetails();
//        JSONObject json = new JSONObject(obj);
//        return json.get("id", Long.class);
//    }
//}
